package ModelLayer;
import java.util.ArrayList;


/**
 * Write a description of class LoanContainer here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class LoanContainer
{
    private ArrayList<Loan> loans;
    private static LoanContainer instance;
    
    private LoanContainer()
    {
        loans = new ArrayList<Loan>();
    }
    
    public static LoanContainer getInstance()
    {  
        if (instance == null)
        {
            instance = new LoanContainer();
            return instance;
        }
        
        return instance;
    }
    
    public void addLoan(Person person, DvdCopy nr, String loanDate, String returnDate)
    {
        Loan l = new Loan(person, nr, loanDate, returnDate);     
        loans.add(l);
    }
    
    public void printAllLoans()
    {
        for(Loan element : loans)
        {
            element.printInformation();
        }
    }
    
     /**
     * This method will take Strings as input to find a loan. It does this by using a search pattern
     * 
     * @ param found    This is a boolean value, that we use to determine if the loan is found or not
     * @ param index    This is an iteger value, that we use to keep track of how far we are in the
     *                  search pattern. 
     */
    public void findLoan(String phone)
    {
        boolean found = false;
        int index = 0;
        while(index < loans.size() && !found)
        {
        Loan l = loans.get(index);
        if(l.getPerson().getPhone().equals(phone))
        {
            l.printInformation();
           
            found = true;
        }
        index++;
       }
    }
    
    
    public void deleteLoan(String phone)
    {
        boolean found = false;
        int index = 0;
        while(index < loans.size() && !found)
        {
        Loan l = loans.get(index);
        if(l.getPerson().getPhone().equals(phone))
        {
            loans.remove(index);
            found = true;
        }
        index++;
       }
    }
}






















